import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import { resolve } from 'path'

// 指定打包模块
let moduleName;
let buildEnv;
// if (
//   (process.argv.length > 3 &&
//     process.argv[process.argv.length - 1].substring(2) !== 'ALL' &&
//     process.argv[process.argv.length - 1].substring(2) !== 'Module') ||
//   process.argv[process.argv.length - 1].substring(0, 2) === '--'
// ) {
//   // 从命令行参数中提取模块名称
//   moduleName = process.argv[process.argv.length - 1].substring(2);
//   // 从命令行参数中提取构建环境
//   buildEnv = process.argv[process.argv.length - 2].substring(2);
// } else {
//   // 若未指定模块名称，则设为空字符串
//   moduleName = '';
// }
console.log('--------moduleName--------', process.argv, moduleName, buildEnv);

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  // build: {
  //   rollupOptions: {
  //     input: {
  //       // main: resolve(__dirname, 'src/main/index.html'),
  //       app1: resolve(__dirname, 'src/views/aichat/index.html'),
  //     },
  //     output: {
  //       dir: 'dist',
  //       compact: true,//该选项用于压缩 Rollup 产生的额外代码。请注意，这个选项不会影响用户的代码。这个选择在构建已经压缩好的代码时是很有用的。
  //       entryFileNames: "assets/js/[name]-[hash].js",
  //       chunkFileNames: "assets/js/[name]-[hash].js",
  //       assetFileNames: "assets/[ext]/[name].[ext]",
  //     }
  //   }
  // },

  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})

